﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SC2parser.Model;

namespace SC2parser.Function
{
    static class stringToPlayer
    {
        /// <summary>
        /// Converts a string from liquipedia to a properly formatted name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string stringToName(this string name)
        {
            //if (name != "" && name[0] == '\'' )
             //   name =name.Substring(3, name.Length - 6);
            return name.Trim(new char[]{' ','\''});
        }

        /// <summary>
        /// Converts a string to the correct race enum
        /// </summary>
        /// <param name="race">The race as string. Use T, P or Z</param>
        /// <returns>The race enum</returns>
        public static Race stringToRace(this string race)
        {
            string raceT = race.Trim();
            if (raceT.ToLower() == "p")
                return Race.Protoss;
            else if (raceT.ToLower() == "t")
                return Race.Terran;
            else if (raceT.ToLower() == "z")
                return Race.Zerg;
            else if (raceT.ToLower() == "r")
                return Race.Random;
            else return Race.Unknown;
        }

        public static string raceToString(this Race race)
        {
            if (race == Race.Protoss)
                return "p";
            else if (race == Race.Terran)
                return "t";
            else return "z";
        }

        public static int stringToWins(this string score)
        {
            try
            {
                return Convert.ToInt32(score);
            }
            catch (FormatException)
            {
                return 0;
            }
        }


    }
}
